﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Motovehiculo

    Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar.Click

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese Dominio.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If


        If (Len(Combomarca.Text) = 0) Then
            MsgBox("Ingrese Marca.", MsgBoxStyle.Exclamation)
            Combomarca.Focus()
            Exit Sub
        End If

        If (Len(txttipo.Text) = 0) Then
            MsgBox("Ingrese Tipo.", MsgBoxStyle.Exclamation)
            txttipo.Focus()
            Exit Sub
        End If

        If (Len(txtmodelo.Text) = 0) Then
            MsgBox("Ingrese Modelo.", MsgBoxStyle.Exclamation)
            txtmodelo.Focus()
            Exit Sub
        End If

        If (Len(txtmarcamotor.Text) = 0) Then
            MsgBox("Ingrese Marca de Motor.", MsgBoxStyle.Exclamation)
            txtmarcamotor.Focus()
            Exit Sub
        End If

        If (Len(txtnummotor.Text) = 0) Then
            MsgBox("Ingrese Número de Motor.", MsgBoxStyle.Exclamation)
            txtnummotor.Focus()
            Exit Sub
        End If

        If (Len(txtmarcachasis.Text) = 0) Then
            MsgBox("Ingrese Número de Chasis.", MsgBoxStyle.Exclamation)
            txtmarcachasis.Focus()
            Exit Sub
        End If

        If (Len(txtnumchasis.Text) = 0) Then
            MsgBox("Ingrese Marca de Chasis.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtuso) = 0) Then
            MsgBox("Ingrese Uso del Vehículo.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If


        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese Dominio del Motovehículo.", MsgBoxStyle.Exclamation, Title:="Error")
            txtdominio.Focus()
            Exit Sub
        End If
        Dim oMotovehiculoNegocios As New Negocios.Nmotovehiculo
        Dim oMotovehiculo As New Entidades.Emotovehiculo
        oMotovehiculo.dominio_mv = UCase(txtdominio.Text)
        oMotovehiculo.marca_mv = UCase(Combomarca.Text)
        oMotovehiculo.tipomv = UCase(txttipo.Text)
        oMotovehiculo.modelo_mv = UCase(txtmodelo.Text)
        oMotovehiculo.marcamotor_mv = UCase(txtmarcamotor.Text)
        oMotovehiculo.nummotor_mv = UCase(txtnummotor.Text)
        oMotovehiculo.numcuadro = UCase(txtnumchasis.Text)
        oMotovehiculo.marcacuadro = UCase(txtmarcachasis.Text)
        oMotovehiculo.usomv = UCase(txtuso.Text)

        Try
            If oMotovehiculoNegocios.guardarmotovehiculo(oMotovehiculo) Then
                MsgBox("Carga Exitosa de Motovehículo.", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If
        Catch ex As Exception
            MsgBox("Carga fallida. " + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try


    End Sub

    Private Sub Motovehiculo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Combomarca.Items.Add("APPIA")
        Combomarca.Items.Add("BAJAJ")
        Combomarca.Items.Add("BETA")
        Combomarca.Items.Add("BETAMOTOR")
        Combomarca.Items.Add("BLACKSTONE")
        Combomarca.Items.Add("BMW")
        Combomarca.Items.Add("BRAVA")
        Combomarca.Items.Add("CERRO")
        Combomarca.Items.Add("CORVEN")
        Combomarca.Items.Add("DA DALT")
        Combomarca.Items.Add("DAELIM")
        Combomarca.Items.Add("DUCATI")
        Combomarca.Items.Add("GARELLI SAHEL")
        Combomarca.Items.Add("GILERA")
        Combomarca.Items.Add("GUERRERO")
        Combomarca.Items.Add("HARLEY DAVIDSON")
        Combomarca.Items.Add("HONDA")
        Combomarca.Items.Add("IMSA")
        Combomarca.Items.Add("JIANSHE")
        Combomarca.Items.Add("JINCHENG")
        Combomarca.Items.Add("JMSTAR")
        Combomarca.Items.Add("KAWASAKI")
        Combomarca.Items.Add("KELLER")
        Combomarca.Items.Add("KIKAI")
        Combomarca.Items.Add("KONISA")
        Combomarca.Items.Add("KTM")
        Combomarca.Items.Add("KYMCO")
        Combomarca.Items.Add("MAVERICK")
        Combomarca.Items.Add("MAVERICK MOTORCYCLES")
        Combomarca.Items.Add("MONDIAL")
        Combomarca.Items.Add("MOTOMEL")
        Combomarca.Items.Add("OKINOI")
        Combomarca.Items.Add("QINGQI")
        Combomarca.Items.Add("ROYAL ENFIELD")
        Combomarca.Items.Add("SUMO")
        Combomarca.Items.Add("SUZUKI")
        Combomarca.Items.Add("TIBO")
        Combomarca.Items.Add("YAMAHA")
        Combomarca.Items.Add("ZANELLA")

    End Sub

    Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
        Me.Close()
        Rodados.Show()
    End Sub

    Private Sub btnmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodificar.Click

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese Dominio.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If


        If (Len(Combomarca.Text) = 0) Then
            MsgBox("Ingrese Marca.", MsgBoxStyle.Exclamation)
            Combomarca.Focus()
            Exit Sub
        End If

        If (Len(txttipo.Text) = 0) Then
            MsgBox("Ingrese Tipo.", MsgBoxStyle.Exclamation)
            txttipo.Focus()
            Exit Sub
        End If

        If (Len(txtmodelo.Text) = 0) Then
            MsgBox("Ingrese Modelo.", MsgBoxStyle.Exclamation)
            txtmodelo.Focus()
            Exit Sub
        End If

        If (Len(txtmarcamotor.Text) = 0) Then
            MsgBox("Ingrese Marca de Motor.", MsgBoxStyle.Exclamation)
            txtmarcamotor.Focus()
            Exit Sub
        End If

        If (Len(txtnummotor.Text) = 0) Then
            MsgBox("Ingrese Número de Motor.", MsgBoxStyle.Exclamation)
            txtnummotor.Focus()
            Exit Sub
        End If

        If (Len(txtmarcachasis.Text) = 0) Then
            MsgBox("Ingrese Número de Chasis.", MsgBoxStyle.Exclamation)
            txtmarcachasis.Focus()
            Exit Sub
        End If

        If (Len(txtnumchasis.Text) = 0) Then
            MsgBox("Ingrese Marca de Chasis.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtuso) = 0) Then
            MsgBox("Ingrese Uso del Vehículo.", MsgBoxStyle.Exclamation)
            txtdominio.Focus()
            Exit Sub
        End If

        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese el Dominio del Motovehículo", MsgBoxStyle.Exclamation, Title:="Error")
            txtdominio.Focus()
            Exit Sub
        End If
        Dim oMotovehiculoNegocios As New Negocios.Nmotovehiculo
        Dim oMotovehiculo As New Entidades.Emotovehiculo
        oMotovehiculo.dominio_mv = UCase(txtdominio.Text)
        oMotovehiculo.marca_mv = UCase(Combomarca.Text)
        oMotovehiculo.tipomv = UCase(txttipo.Text)
        oMotovehiculo.modelo_mv = UCase(txtmodelo.Text)
        oMotovehiculo.marcamotor_mv = UCase(txtmarcamotor.Text)
        oMotovehiculo.nummotor_mv = UCase(txtnummotor.Text)
        oMotovehiculo.numcuadro = UCase(txtnumchasis.Text)
        oMotovehiculo.marcacuadro = UCase(txtmarcachasis.Text)
        oMotovehiculo.usomv = UCase(txtuso.Text)
        Try
            If oMotovehiculoNegocios.modificarmotovehiculo(oMotovehiculo) Then
                MsgBox("Modificación Exitosa de Motovehículos.", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If

        Catch ex As Exception
            MsgBox("Los datos no han sido modificados." + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try

    End Sub

    Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese el Dominio del Motovehículo", MsgBoxStyle.Exclamation, Title:="Error")
            txtdominio.Focus()
            Exit Sub
        End If
        Dim oMotovehiculoNegocios As New Negocios.Nmotovehiculo
        Dim oMotovehiculo As New Entidades.Emotovehiculo
        oMotovehiculo.dominio_mv = UCase(txtdominio.Text)
        Try
            If oMotovehiculoNegocios.eliminarmotovehiculo(oMotovehiculo) Then
                MsgBox("Los datos han sido eliminados.", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If
        Catch ex As Exception
            MsgBox("Los datos no han sido eliminados." + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try
    End Sub

    Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbusqueda.Click
        If (Len(txtdominio.Text) = 0) Then
            MsgBox("Ingrese el dominio del Motovehículo a Buscar", MsgBoxStyle.Exclamation, Title:="Error")
            txtdominio.Focus()
            Exit Sub
        End If




        If Not IsNumeric(txtbusqueda.Text) Then
            MsgBox("Ingrese el dominio del Motovehículo a Buscar", MsgBoxStyle.DefaultButton1, Title:="Error")
            Exit Sub
        End If


        Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim DT As New DataTable
        Dim DR As DataRow
        Dim cn As New SqlConnection
        Dim csn As String = "Data Source=ROSA\SQLEXPRESS;database=gestion mandatario nacional del automotor;uid=sa;pwd=123456"
        cn = New SqlConnection(csn)
        da = New SqlDataAdapter("sp_buscarmotovehiculo", cn)
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        ds = New DataSet
        da.Fill(ds, "datos")
        gvmotovehiculo.DataSource = ds.Tables("datos").DefaultView

        If DT.Rows.Count > 0 Then
            DR = DT.Rows(0)
            txtdominio.Text = DR.Item("dominio")
            Combomarca.Text = DR.Item("marca")
            txttipo.Text = DR.Item("tipo")
            txtmodelo.Text = DR.Item("modelo")
            txtmarcamotor.Text = DR.Item("marca_motor")
            txtnummotor.Text = DR.Item("num_motor")
            txtmarcachasis.Text = DR.Item("marca_cuadro")
            txtnumchasis.Text = DR.Item("num_cuadro")
            txtuso.Text = DR.Item("uso")

        Else
            MsgBox("El Motovehículo no existe", MsgBoxStyle.DefaultButton1)
        End If


        Dim oMotovehiculoNegocios As New Negocios.Nmotovehiculo
        Dim oMotovehiculo As New Entidades.Emotovehiculo
        gvmotovehiculo.DataSource = oMotovehiculoNegocios.buscarmotovehiculo(txtbusqueda.Text)
        txtbusqueda.Text = ""
    End Sub

    Private Sub btnblanquear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnblanquear.Click
        Dim oMotovehiculoNegocios As New Negocios.Nmotovehiculo
        Dim oMotovehiculo As New Entidades.Emotovehiculo
        txtdominio.Text = ""
        Combomarca.Text = ""
        txttipo.Text = ""
        txtdominio.Text = ""
        txtmodelo.Text = ""
        txtmarcamotor.Text = ""
        txtnummotor.Text = ""
        txtnumchasis.Text = ""
        txtmarcachasis.Text = ""
        txtuso.Text = ""
        txtdominio.Focus()
    End Sub


End Class